<template>
	<div>
		<el-tabs v-model="activeName" @tab-click="handleTabChange">
			<el-tab-pane v-for="(item, index) in tabsList" :key="index" :label="item.label" :name="item.value"></el-tab-pane>

			<div class="content-card">
				<component
					v-if="!loading"
					class="pd10"
					:is="whickComm[activeName]"
					@refresh="handleRefresh"
					:nowRowData="nowRowData"
					:key="activeName"
				></component>
			</div>
		</el-tabs>
	</div>
</template>

<script setup lang="ts">
import Extend from './Extend/index.vue'
import BaseDetail from './BaseDetail/index.vue'
import ObjectOther from './ObjectOther/index.vue'
import apiMod from '@/apiMod'
import { useCommonStore } from '@/stores/common'

const { setMoreSearch,setLoading } = useCommonStore()

const whickComm = {
	BaseDetail,
	Extend,
	ObjectOther,
}
type Props = {
	nowRowData?: any
}
const props = withDefaults(defineProps<Props>(), {})
const emit = defineEmits(['refresh', 'rechange'])

const activeLabelTitle = ref('基础信息')
const loading = ref(false)
const tabsList: any = [
	{ label: '基础信息', value: 'BaseDetail' },
	{ label: '扩展信息', value: 'Extend' },
	{ label: '其他信息', value: 'ObjectOther' },
]
const activeName = ref('BaseDetail')
let nowData = ref({})
provide('nowRowData', nowData)

const getInitData = () => {
	loading.value = true
  setLoading(true)
	if (props.nowRowData?.idCard) {
		apiMod
			.view_dpServiceObjectFile_all({
				idCard: props.nowRowData?.idCard,
			})
			.then((res) => {
        setLoading(false)
				loading.value = false
				const data = {
					dpServiceObjects: res.data.dpServiceObjectFile || {},
					dpServiceObjectExtends: res.data.dpServiceObjectExtendFile || {},
					dpServiceObjectOthers: res.data.dpServiceObjectOtherFile|| {},
					dpServiceObjectMaterials: res.data.dpServiceObjectMaterialFileList||[],
					dpServiceObjectContacts: res.data.dpServiceObjectContactFileList||[],
				}
				nowData.value = data
			})
			.catch((err) => {
				loading.value = false
			})
	}
}

const handleRefresh = () => {
	emit('refresh')
}
const handleTabChange = (tab) => {
	activeLabelTitle.value = tab.props.label
	setMoreSearch({
		params: {
			idCard: props.nowRowData.idCard,
			creditCode: props.nowRowData.creditCode,
		},
	})
}

onMounted(() => {
	getInitData()
})
onUnmounted(() => {
	setMoreSearch({})
})
</script>

<style scoped></style>
